<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>test_promise</title>
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
  
</body>

<script type="module">
  import {getUser, getGoods, getAppraise} from './common.js'

  function ready() {
    // promise链式调用
    // getUser().then(res => {
    //   let userId = res.data[0].id
    //   return getGoods(userId)
    // }).then(res => {
    //   let goodsId = res.data[0].userId
    //   return getAppraise(goodsId)
    // }).then(res => {
    //   console.log(res.data[0]);
    // })

    // getUser().then(res => {console.log('user完成')})
    // getGoods(1).then(res => {console.log('goods完成')})
    // getAppraise(1).then(res => {console.log('appraise完成')})

    let p1 = getUser()
    let p2 = getGoods(1)
    let p3 = getAppraise(1)
    // 执行完成后统一处理
    Promise.all([p1, p2, p3]).then(res => {
      console.log('end')
    })

  }

  ready()
</script>
</html>